<body class="gr">

<div class="navBar">
	<a class="left" href="wap.php?app=member&act=index"><i class="return"></i></a>
	<div class="titleView">积分商城订单</div>
</div>

<div class="member-order member-mall-order main-padding-top">
	<div class="pullRefresh overflow-scroll">
		{if count($data)>0}
		<ul class="list tableView tableView-noLine">
			{foreach from=$data name=g item=g}
			<li>
				<div class="view">
					<a href="?app=member&act=order_detail&integral_order=1&id={$g->id}">
						<div class="status ge-bottom ge-light status{$g->status}"><font>订单号：{$g->order_sn}</font><div>{$g->status}</div>{if $g->status>0 && $g->ask_refund_time>0}<span>(退货退款中)</span>{/if}</div>
						<ul>
							{foreach from=$g->goods name=p item=p}
							<li>
								<div class="gview">
									<div class="pic" style="background-image:url({$p->goods_pic});"></div>
									<div class="name">{$p->goods_name}</div>
									<div class="spec">
										<span class="price">{$p->integral}积分</span>
									</div>
								</div>
							</li>
							{/foreach}
						</ul>
					</a>
				</div>
			</li>
			{/foreach}
		</ul>
		{else}
		<div class="norecord">当前没有任何订单</div>
		{/if}
	</div>
</div>

<script>
var offset = $('.pullRefresh .list > li').length;
function createHtml(g){
	var html = '<li>\
		<div class="view">\
			<a href="?app=member&act=order_detail&integral_order=1&id='+g.id+'">\
				<div class="status ge-bottom ge-light status'+g.status+'"><font>订单号：'+g.order_sn+'</font><div>'+statusName(g.status)+'</div>'+((g.status>0 && g.ask_refund_time>0)?'<span>(退货退款中)</span>':'')+'</div>\
				<ul>';
				for(var i=0; i<g.goods.length; i++){
				html += '<li>\
						<div class="gview">\
							<div class="pic" style="background-image:url('+g.goods[i].goods_pic+');"></div>\
							<div class="name">'+g.goods[i].goods_name+'</div>\
							<div class="spec"><span class="price">'+g.goods[i].integral+'积分</span></div>\
						</div>\
					</li>';
				}
				html += '</ul>\
			</a>\
		</div>\
	</li>';
	offset++;
	return html;
}
function statusName(status){
	var name = '';
	switch(status*1){
		case -3:name = '已退货';break;
		case -2:name = '已退款';break;
		case -1:name = '取消';break;
		case 0:name = '待付款';break;
		case 1:name = '待发货';break;
		case 2:name = '待收货';break;
		case 3:
		case 4:name = '完成';break;
	}
	return name;
}
function setInfo(){
	$('.gview .pic').loadbackground();
}
$(function(){
	$('.member-order').height($.window().height-$('.member-order').padding().top);
	$('.tableView .status div').html(function(i, html){ return statusName(html) });
	setInfo();
	$('.pullRefresh').pullRefresh({
		header : true,
		footer : true,
		footerNoMoreText : '- END -',
		refresh : function(fn){
			var _this = this;
			offset = 0;
			$.getJSON('api.php?app=member&act=order&integral_order=1&status='+_this.attr('status'), function(json){
				if(json.error!=0){ $.overloadError(json.msg);return }
				var html = '';
				if($.isArray(json.data))for(var i=0; i<json.data.length; i++)html += createHtml(json.data[i]);
				_this.find('.tableView').html(html);
				setInfo();
				fn();
			});
		},
		load : function(fn){
			var _this = this;
			$.getJSON('api.php?app=member&act=order&integral_order=1&status='+_this.attr('status'), { offset:offset }, function(json){
				if(json.error!=0){ $.overloadError(json.msg);return }
				var html = '';
				if($.isArray(json.data))for(var i=0; i<json.data.length; i++)html += createHtml(json.data[i]);
				_this.find('.tableView').append(html);
				setInfo();
				fn();
			});
		}
	});
});
</script>